package com.kfm.pm.linkedList;

import java.util.LinkedList;

public class LinkedListTest {

    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        linkedList.add("a");
        linkedList.add("b");
        linkedList.add("c");
//        linkedList.add("d");
        linkedList.add("c");
        linkedList.add("b");
        linkedList.add("a");
        System.out.println(isPalindromic(linkedList));
        linkedList.forEach(object -> System.out.println(object));
    }

    private static boolean isPalindromic(LinkedList linkedList) {
        // a b cdc c a
        LinkedList list = (LinkedList) linkedList.clone();
        if (list.size() <= 1) {
            return true;
        }
        while (true) {
            if (list.size() <= 1) {
                return true;
            }
            if (list.getFirst().equals(list.getLast())) {
                list.removeFirst();
                list.removeLast();
            } else {
                return false;
            }
//            if (!list.removeFirst().equals(list.removeLast())) {
//                return false;
//            }
        }
    }
}
